package com.sc;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author: shichong1008@outlook.com
 * @Description: TODO
 * @DateTime: 2023/10/18 16:18
 **/
@Component
public class SpringRabbitListener {

    @RabbitListener(queues = "test.queue")
    public void ListenQueue(Message msg, Channel channel) {
        try {
            channel.basicReject(msg.getMessageProperties().getDeliveryTag(), false);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        System.out.println("消费者接收到 simple.queue 的消息:" + msg);
    }
}